欢迎使用零点宝宝起名,一款免费的宝宝起名工具。
男
女
(function () {const form = document.getElementById('name-form');const results = document.getElementById('results');const resultsHeading = document.getElementById('results-heading');const nameList = document.getElementById('name-list');form.addEventListener('submit', (e) => {e.preventDefault();const surname = document.getElementById('surname').value;const gender = document.getElementById('gender').value;const birthYear = document.getElementById('birth-year').value;const birthMonth = document.getElementById('birth-month').value;const birthDay = document.getElementById('birth-day').value;const birthHour = document.getElementById('birth-hour').value;if (!surname || !birthYear || !birthMonth || !birthDay || !birthHour) {alert('请填写所有必填项。');return;}const data = {surname: surname,gender: gender,birthYear: parseInt(birthYear),birthMonth: parseInt(birthMonth),birthDay: parseInt(birthDay),birthHour: parseInt(birthHour),};fetch('https://localhost:5000/api/names', {method: 'POST',headers: {'Content-Type': 'application/json',},body: JSON.stringify(data),}).then((res) => res.json()).then((data) => {if (data.success) {results.style.display = 'block';resultsHeading.innerText = `为您生成的名字:`;nameList.innerHTML = '';data.names.forEach((name) => {const li = document.createElement('li');li.classList.add('name-item');li.innerText = name;nameList.appendChild(li);});} else {alert(data.message);}}).catch((error) => {console.error('Error querying API: ', error);alert('抱歉,出错了。请稍后再试。');});});})();